package com.tgy.plus1.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/***
 * @ClassName: TimeHandler
 * @Description:
 * @Auther: 送你一块二向箔
 * @Date: 14:52 2022/3/25
 * @version : V1.0
 */
@Slf4j
@Component//丢到springboot里   一定不要忘记把处理器加到Ioc容器中!
public class TimeHandler implements MetaObjectHandler {



    @Override//插入时的填充策略
    public void insertFill(MetaObject metaObject) {
        log.error("==start insert ······==");
        //setFieldValByName(java.lang.String fieldName, java.lang.Object fieldVal, org.apache.ibatis.reflection.MetaObject metaObject)
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐使用)
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐使用)

    }
    @Override//更新时的填充策略
    public void updateFill(MetaObject metaObject) {
        log.info("==start update ······==");
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
    }
}
